package com.example.paper.loginreg;

import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.ImageView;
import android.widget.Toast;

import androidx.appcompat.app.AppCompatActivity;

import com.example.db.DBManager;
import com.example.db.DaoSession;
import com.example.db.Goods;
import com.example.db.GoodsDao;
import com.example.paper.R;

import java.util.List;

public class ChangeNameActivity extends AppCompatActivity {

    private ImageView backUpName;
    private EditText nickName;
    private Button checkNamenick;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_change_name);
        initView();

        //保存
        checkNamenick.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                String name = nickName.getText().toString().trim();
                if (name.equals("")){
                    Toast.makeText(ChangeNameActivity.this, "用户名不能为空", Toast.LENGTH_SHORT).show();
                }else {
                    //发送广播
                    Intent intent = new Intent();
                    intent.setAction("sends_user_name");
                    intent.putExtra("send_userName",name);
                    sendBroadcast(intent);
                    finish();
                }
            }
        });

        //退出
        backUpName.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                finish();
            }
        });

    }

    private void initView() {
        backUpName = (ImageView) findViewById(R.id.back_up_name);
        nickName = (EditText) findViewById(R.id.nick_name);
        checkNamenick = (Button) findViewById(R.id.check_namenick);
    }
}